﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsUserControl.Codes
{
    /// <summary>
    /// 
    /// </summary>
    public partial class CodeEditor : Form
    {
        public delegate void OnCodeUpdated(string code);

        public event OnCodeUpdated CodeUpdated;

        private string methodSignature;

        public CodeEditor(string signature)
        {
            InitializeComponent();
            this.methodSignature = signature;
        }

        private void CodeEditor_Load(object sender, EventArgs e)
        {
            this.txt_Signature.Text = methodSignature;
        }

        public string Code
        {
            get
            {
                return this.rt_Code.Text;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                    this.rt_Code.Text = string.Empty;
                else
                    this.rt_Code.Text = value;
            }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (this.CodeUpdated != null)
                this.CodeUpdated(this.rt_Code.Text);
            this.Close();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
